/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package mappers;

import handler.DatabaseConnection;
import java.io.FileNotFoundException;
import java.sql.Date;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Calendar;
import model.ProductionRequest;

/* @author Benjamin */

public class ProductionRequestMapper {

    private static ProductionRequestMapper instance;
    
    public ArrayList<ProductionRequest> getProductionRequests() throws SQLException, FileNotFoundException{
        ArrayList<ProductionRequest> productionRequests = new ArrayList<>();
        
        Statement stmt = DatabaseConnection.getInstance().getInstance().getConnection().createStatement();
        
        String sql = "select * from productionRequest";
        
        ResultSet rs = stmt.executeQuery(sql);
        
        while (rs.next()){
            int id = rs.getInt("id");
            Date productionStart = rs.getDate("productionStart");
            Date ETA = rs.getDate("ETA");
            
            productionRequests.add(new ProductionRequest(id, productionStart, ETA));
        }
        
        return productionRequests;
    }
    
    public static ProductionRequestMapper getInstance(){
        if(instance == null){
            instance = new ProductionRequestMapper();
        }
        return instance;
    }
}
